<template>
  <div>
    <a-spin :spinning="loading">
      <top-nav-bar :applyPageRoute="nowRouteTitle" @back="back"></top-nav-bar>
      <a-card :bordered="false" class="nowPage">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <p>
              <span style="padding-right:5px">考试名称:</span>
              {{ data.name }}
            </p>
          </a-col>
          <a-col :md="8" :sm="24">
            <p>
              <span style="padding-right:5px">考试科目:</span>
              {{ data.subject_name }}
            </p>
          </a-col>
          <a-col :md="6" :sm="24">
            <p>
              <span style="padding-right:5px">满分:</span>
              {{ data.full_marks }}
            </p>
          </a-col>
          <a-col :md="2" :sm="24">
            <a-button type="primary" @click="gotoEdit">编辑成绩单</a-button>
          </a-col>
          <a-col :span="24"></a-col>
          <a-col :md="8" :sm="24">
            <p>
              <span style="padding-right:5px">考试时间:</span>
              {{ data.time }}
            </p>
          </a-col>
          <a-col :md="8" :sm="24">
            <p>
              <span style="padding-right:5px">考试来源:</span>
              {{ data.source_type==1?'机构内':'机构外' }}
            </p>
          </a-col>
          <a-col :span="24">
            <div class="a_row_bottom"></div>
          </a-col>
          <a-col :md="8" :sm="24">
            <p>
              <span style="padding-right:5px">是否展示给家长:</span>
              {{ data.is_show==1?'展示':'不展示' }}
            </p>
          </a-col>
          <a-col :md="8" :sm="24">
            <p>
              <span style="padding-right:5px">排名、最高分、平均分是否展示给家长:</span>
              {{ data.is_statistics_show==1?'展示':'不展示' }}
            </p>
          </a-col>
        </a-row>
      </a-card>
      <a-card :bordered="false" style="margin-top:25px">
        <a-alert
          :message="'最高分：'+data.highest_score+'分 平均分：'+data.average_score+'分'"
          type="warning"
          showIcon
          style="border:none;"
        />
        <div style="margin-top:15px;">
          <a-table
            :columns="columns"
            :dataSource="data.score_arr"
            class="user_management_table"
            style="border: 1px solid #e8e8e8;"
            :pagination="false"
            :rowKey="(record) => record.id"
          >

            <div slot="comment" slot-scope="text,record">
              {{ record.comment||'-' }}
            </div>
          </a-table>
        </div>
      </a-card>
    </a-spin>
  </div>
</template>

<script>
import moment from 'moment'
// import { STable, Ellipsis } from '@/components'
// import StepByStepModal from '../../list/modules/StepByStepModal'
// import CreateForm from '../../list/modules/CreateForm'
import { clockincreate, getExams } from '@/api/homeSchool'
import { classList } from '@/api/class'

import topNavBar from '@/components/topNavBar/topNavBar'

export default {
  name: 'Single',
  components: {
    topNavBar
  },
  data () {
    return {
      loading: false,
      nowRouteTitle: '',
      Isclass: [],
      // rules: {
      //   school_id: [{ required: true, message: '请选择', trigger: 'change' }],
      //   title: [{ required: true, message: '请输入内容', trigger: 'blur' }]
      // },
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      data: {},
      columns: [
        {
          title: '学员姓名',
          dataIndex: 'student_name'

        },
        {
          title: '分数',
          dataIndex: 'score'

        },
        {
          title: '排名',
          dataIndex: 'rank'

        },
        {
          title: '评语(选填)',

          scopedSlots: { customRender: 'comment' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: []
    }
  },
  created () {},
  mounted () {
    classList({ pageSize: 999999 }).then(res => {
      this.Isclass = res.data
    })
    this.$store.state.Isfather = false
    this.nowRouteTitle = this.$route.meta.title
    const d = new Date()
    this.data.title = d.getMonth() + 1 + '月' + d.getDate() + '日' + '作业'
    this.data.school_id = this.$store.state.user.school
    const id = this.$route.query.id
    this.getScoreInfo()
  },
  destroyed () {
    this.$store.state.Isfather = true
  },
  methods: {
    getScoreInfo(){
      this.loading=true
      getExams(this.$route.query.id).then(res => {
      this.data = res
      // this.loadData = [res]
    }).catch(err=>{
      this.$message.error(err.data.message||'成绩详情获取失败')
    }).finally(()=>{
      this.loading=false
    })
    },
    gotoEdit () {
      // this.$store.state.Isfather = false
      // this.$router.push({ name: 'reportCardEdit' })
      this.$router.push({ name: 'edit_record', query: { id: this.$route.query.id } })
    },
    back () {
      this.$router.go('-1')
    },

  }
}
</script>
<style lang="less" scoped>
.nowPage {
  padding: 0 8px;
}
.a_row_bottom {
  border-bottom: 1px solid #e8e8e8;
  width: 100%;
  margin: 10px 0;
}
</style>
